using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RepeaterPagingPage : System.Web.UI.Page
{
    int pageSize = 2;
    ControlProviders controlProviders;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblPage.Text = "1";
           
            controlProviders = new ControlProviders();
            int rows = controlProviders.FillRecruiterAccount(this.Repeater1,
            pageSize);
            lblPages.Text = (rows / pageSize + ((rows % pageSize) > 0 ? 1 : 0)).ToString();
             
            linkPrevious.Enabled = false;
            linkFirst.Enabled = false;
        }
    }


    protected void linkFirst_Click(object sender, EventArgs e)
    {
        controlProviders = new ControlProviders();
        controlProviders.FillRecruiterAccount(this.Repeater1, 0, pageSize);
        lblPage.Text = "1";        
        linkPrevious.Enabled = false;
        linkFirst.Enabled = false;
        linkNext.Enabled = true;
        linkLast.Enabled = true;
    }
    protected void linkPrevious_Click(object sender, EventArgs e)
    {
        linkNext.Enabled = true;
        linkLast.Enabled = true;
        int currentPage = Convert.ToInt32(lblPage.Text);
        if (currentPage > 1) currentPage--;
        controlProviders = new ControlProviders();
        controlProviders.FillRecruiterAccount(this.Repeater1,
    (currentPage - 1) * pageSize, pageSize);
        lblPage.Text = currentPage.ToString();
        
        if (currentPage == 1)
        {
            linkPrevious.Enabled = false;
            linkFirst.Enabled = false;
        }
        else
        {
            linkFirst.Enabled = true;
            linkPrevious.Enabled = true;
        }
    }

    protected void linkNext_Click(object sender, EventArgs e)
    {
        linkFirst.Enabled = true;
        linkPrevious.Enabled = true;
        int currentPage = Convert.ToInt32(lblPage.Text);
        if (currentPage > 0) currentPage++;
        controlProviders = new ControlProviders();
        controlProviders.FillRecruiterAccount(
            this.Repeater1,(currentPage - 1) * pageSize, 
        pageSize);
        lblPage.Text = currentPage.ToString();
       
        if (currentPage == Convert.ToInt32(lblPages.Text))
        {
            linkLast.Enabled = false;
            linkNext.Enabled = false;
        }
        else
        {
            linkLast.Enabled = true;
            linkNext.Enabled = true;
        }
    }


    protected void linkLast_Click(object sender, EventArgs e)
    {
        linkNext.Enabled = false;
        linkLast.Enabled = false;
        linkFirst.Enabled = true;
        linkPrevious.Enabled = true;
        controlProviders = new ControlProviders();
        controlProviders.FillRecruiterAccount(this.Repeater1, (Convert.ToInt32(lblPages.Text) - 1) * pageSize, pageSize);
        lblPage.Text = lblPages.Text;
        
    }
}
